###################
### ENVIRONMENT ###
###################
import os
import sys

### LOAD GSLAB MAKE
ROOT = '..'
gslm_path = os.path.join(ROOT, 'lib', 'gslab_make')

sys.path.append(gslm_path)
import gslab_make as gs

### PULL PATHS FROM CONFIG
PATHS = {
    'root'             : ROOT,
    'lib'              : os.path.join(ROOT, 'lib'),
    'config'           : os.path.join(ROOT, 'config.yaml'),
    'config_user'      : os.path.join(ROOT, 'config_user.yaml'),
    'input_dir'        : 'input', 
    'external_dir'     : 'external',
    'output_dir'       : 'output',
    'output_local_dir' : 'output_local',
    'makelog'          : 'log/make.log',         
    'output_statslog'  : 'log/output_stats.log', 
    'source_maplog'    : 'log/source_map.log',  
    'source_statslog'  : 'log/source_stats.log',
    'reply_cover'      : 'reply/cover.lyx'
}
PATHS = gs.update_internal_paths(PATHS)

### LOAD CONFIG USER 
PATHS = gs.update_external_paths(PATHS)
gs.update_executables(PATHS)

############
### MAKE ###
############

### START MAKE
gs.remove_dir(['input', 'external'])
gs.clear_dir(['output', 'log'])
gs.start_makelog(PATHS)

## MAKE LINKS TO INPUT AND EXTERNAL FILES
inputs = gs.copy_inputs(PATHS, ['input.txt'])
externals = gs.copy_externals(PATHS, ['external.txt'])
gs.write_source_logs(PATHS, inputs + externals)
#gs.get_modified_sources(PATHS, inputs + externals)

## RUN SCRIPTS
gs.run_lyx(PATHS, program = 'code/includedIV.lyx')

### LOG OUTPUTS
gs.log_files_in_output(PATHS)

### CHECK FILE SIZES
#gs.check_module_size(PATHS)

### END MAKE
gs.end_makelog(PATHS)
